﻿package mortal.game.view.common.display
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.geom.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class StarPanel extends GSprite
    {
        private var _starAmount:int;
        private var _value:Number;
        private var _starList:Vector.<GBitmap>;
        private var _brightUrl:String = "GuildWarStarM";
        private var _darkUrl:String = "GuildWarStarMGray";
        private var _gat:int = 29;
        private var _isLoadCompl:Boolean = false;
        protected var _brightBitmapData:BitmapData;
        protected var _darkBitmapData:BitmapData;
        public static var _arySuffix:Array = [".png", ".jpg", ".jpeg", ".swf"];

        public function StarPanel()
        {
            this._starList = new Vector.<GBitmap>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._starAmount = 0;
            this._value = 0;
            var _loc_2:* = this._starList.length - 1;
            while (_loc_2 >= 0)
            {
                
                this._starList[_loc_2].dispose(param1);
                _loc_2 = _loc_2 - 1;
            }
            this._starList.length = 0;
            this._brightUrl = ImagesConst.GuildWarStarM;
            this._darkUrl = ImagesConst.GuildWarStarMGray;
            this._gat = 29;
            this._isLoadCompl = false;
            if (this._brightBitmapData)
            {
                this._brightBitmapData = null;
            }
            if (this._darkBitmapData)
            {
                this._darkBitmapData = null;
            }
            return;
        }// end function

        public function setStarStyle(param1:String, param2:String, param3:int) : void
        {
            var brightUrl:* = param1;
            var darkUrl:* = param2;
            var gat:* = param3;
            this._brightUrl = brightUrl;
            this._darkUrl = darkUrl;
            this._gat = gat;
            LoaderManager.instance.load(getUrl(this._brightUrl), function (param1) : void
            {
                _brightBitmapData = param1.bitmapData as BitmapData;
                drawStar();
                return;
            }// end function
            , 3);
            LoaderManager.instance.load(getUrl(this._darkUrl), function (param1) : void
            {
                _darkBitmapData = param1.bitmapData as BitmapData;
                drawStar();
                return;
            }// end function
            , 3);
            return;
        }// end function

        protected function setBitmapdata(param1:String, param2:BitmapData) : void
        {
            var url:* = param1;
            var bitmapData:* = param2;
            LoaderManager.instance.load(url, function (param1) : void
            {
                bitmapData = (param1.bitmapData as BitmapData).clone();
                drawStar();
                return;
            }// end function
            , 3);
            return;
        }// end function

        public function setStarNum(param1:uint, param2:Number) : void
        {
            this._starAmount = param1;
            this._value = param2;
            if (this._starAmount < 0)
            {
                this._starAmount = 0;
            }
            if (param2 < 0)
            {
                param2 = 0;
            }
            this.drawStar();
            return;
        }// end function

        public function get totalStar() : int
        {
            return this._starAmount;
        }// end function

        public function get value() : Number
        {
            return this._value;
        }// end function

        public function get gat() : int
        {
            return this._gat;
        }// end function

        protected function drawStar() : void
        {
            var _loc_1:GBitmap = null;
            var _loc_2:int = 0;
            var _loc_3:BitmapData = null;
            var _loc_4:int = 0;
            if (this._brightBitmapData && this._darkBitmapData && this._starAmount)
            {
                _loc_2 = this._starList.length - 1;
                while (_loc_2 >= this._starAmount)
                {
                    
                    this._starList[_loc_2].dispose();
                    var _loc_5:* = this._starList;
                    var _loc_6:* = this._starList.length - 1;
                    _loc_5.length = _loc_6;
                    _loc_2 = _loc_2 - 1;
                }
                _loc_2 = this._starList.length;
                while (_loc_2 < this._starAmount)
                {
                    
                    _loc_1 = UIFactory.gBitmap("", _loc_2 * this._gat, 0, this);
                    this._starList.push(_loc_1);
                    _loc_2++;
                }
                _loc_2 = 0;
                while (_loc_2 < Math.floor(this._value))
                {
                    
                    this._starList[_loc_2].bitmapData = this._brightBitmapData;
                    this._starList[_loc_2].smoothing = true;
                    _loc_2++;
                }
                _loc_2 = Math.floor(this._value);
                while (_loc_2 < Math.ceil(this._value))
                {
                    
                    _loc_3 = this._darkBitmapData.clone();
                    _loc_4 = (this._value - Math.floor(this._value)) * this._brightBitmapData.width;
                    _loc_3.draw(this._brightBitmapData, new Matrix(1, 0, 0, 1, 0, 0), null, null, new Rectangle(0, 0, _loc_4, this._brightBitmapData.height));
                    this._starList[_loc_2].bitmapData = _loc_3;
                    this._starList[_loc_2].smoothing = true;
                    _loc_2++;
                }
                _loc_2 = Math.ceil(this._value);
                while (_loc_2 < this._starAmount)
                {
                    
                    this._starList[_loc_2].bitmapData = this._darkBitmapData;
                    this._starList[_loc_2].smoothing = true;
                    _loc_2++;
                }
            }
            return;
        }// end function

        public static function getUrl(param1:String) : String
        {
            var _loc_3:String = null;
            var _loc_2:* = param1.toLocaleLowerCase();
            for each (_loc_3 in _arySuffix)
            {
                
                if (_loc_2.indexOf(_loc_3) > 0)
                {
                    return param1;
                }
            }
            return param1 + ".swf";
        }// end function

    }
}
